All Questions
22 questions
2votes
1answer
204views
Sorting an assortment of strings and integers together, while keeping them separate
I put a solution to this coding problem together. The problem is this: Create a function that takes an array, finds the most often repeated element(s) within it and returns it/them in an array. The ...
4votes
1answer
245views
Recursive Ruby merge sort
I have implemented a merge sort in Ruby. (Yes, I know, there's Array#sort) I would like to get feedback on code quality and optimization. ...
3votes
2answers
244views
Alphabetically sorted numbers
This exercise involves taking an array of numbers and sorting them alphabetically. For example, [1,2,3,4] would return as [4,1,3,2] I mapped the array first, returning an array of words, then sorted ...
2votes
2answers
211views
Given an arbitrarily large file containing integers, return the largest N numbers, highest first
I've written a top_n program in Ruby, which does pretty much exactly what the title says, as part of a coding exercise. I'm trying to learn about how to sort ...
0votes
1answer
180views
Merge sort for an integer array in Ruby
I've implemented merge sort an integer array. Should I change them to more meaningful names? Overall, any further suggestions on this code? I would like to improve my coding style and to shorten the ...
8votes
0answers
128views
Stable variation of built-in sort
Ruby's built-in sorts are unstable. The stable_sort gem monkey-patches Ruby's built-in library to have stable sorts which include nearly all the functionality of the built-in sorts, but with the ...
3votes
2answers
400views
Ruby bubble sort algorithm
I'm just looking for constructive criticism of my Ruby implementation of a bubble sort algorithm. ...
4votes
3answers
5kviews
Sort array of hashes with nil values last
I wrote a method which sorts an array of hashes by given hash keys. The method should put nil values at the end. ...
4votes
3answers
264views
Generate word list based on Spanish text file
I'm a beginner and wrote a program that takes a text file and writes a downcased vocabulary list to another text file. I intend to use it mainly to work with text in Spanish, so I added a line to ...
4votes
2answers
2kviews
Rails conditional sorting based on params
The following code sorts the current users bid model items based on a param condition :bid_status. It starts to get messy when checking if the project space (...
4votes
2answers
360views
Ruby Interrupted Bubble Sort
Working through CodeEval's Interrupted Bubble Sort, I have a working algorithm, but there's a speed issue. I'm trying to do this with Ruby and I keep getting an error that it's timing out after 10 ...
7votes
2answers
436views
Bubble sort in Ruby
For practice, I tried implementing Bubble sort in Ruby. I wasn't very sure how nested for loops would look like in Ruby. Is this the 'right way' to do this in Ruby? I found this question, but it looks ...
0votes
1answer
108views
Reducing the sorting time of a large number of numbers
I have to sort many large numbers in a given time limit. The program below works, but not when the test cases reaches \$10^6\$, in which case it exceeds the time limit. ...
7votes
2answers
2kviews
A Ruby sorting program for multiple criteria
This code review expands on an earlier one that deals with generating a football table from match data. This review deals with ordering said table based on several criteria. Your opinions/...
3votes
3answers
418views
Speed up counting sort algorithm in Ruby
I'm attempting this simple HackerRank counting sort problem but testcase #3, which has 100,000 test cases, is timing out. Is there something particularly inefficient about this code? ...